mkdir -p checkpoint_filtered
mkdir -p log

CKPT_DIR=$1
CKPT_PREFIX=$2
PROCESS_NUM=$3
NODE_NUM=${4:-1}
NODE_ID=${5:-0}

GAP=$((PROCESS_NUM/NODE_NUM))
START_RANK_ID=$((NODE_ID*GAP))

if [ "$NODE_NUM" -eq 1 ] && [ "$NODE_ID" -eq 0 ]; then
    echo "Using default values for NODE_NUM and NODE_ID."
fi

for((i=$START_RANK_ID;i<$((START_RANK_ID+GAP));i++))
do
    export RANK_ID=$i
    echo "start process_$i"
    python filter_ckpts.py --checkpoint_dir $CKPT_DIR --ckpt_prefix $CKPT_PREFIX --process_num $PROCESS_NUM --filter_mode eval \
    &> ./log/filter_$i.log 2>&1 &
done

wait
